<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018\12\3 0003
 * Time: 15:50
 */
error_reporting(0);
header('Access-Control-Allow-Origin:*');

$domain = "http://swoole.upload.guardevil.cn";
$result=array ("success"=>false,"message"=>"Null");
$file_size_limit=300*1024; // 300KB
if (in_array($_FILES["imageFile"]["type"],array ("image/gif","image/jpeg","image/pjpeg","image/png"))){
    if ($_FILES["imageFile"]["error"]>0){
        $result['message']="error";
    }
    elseif ($_FILES["imageFile"]["size"]>$file_size_limit){
        $result['message']="File too large";
    }else {
        $file_name="upload/".md5_file($_FILES["imageFile"]["tmp_name"]).str_replace("image/",".",$_FILES["imageFile"]["type"]);
        if (!file_exists($file_name)){
            move_uploaded_file($_FILES["imageFile"]["tmp_name"],$file_name);
        }
        $result['success']=true;
        $result['message']=$file_name;
        $result['url'] = $domain . '/' . $file_name;
    }
}else {
    $result['message']="Invalid file";
}
return $result;